﻿/*
 *  XTL - XNA Tool Library, a collection with usefull XNA classes
 * 
 *  Copyright (C) 2009 Sebastian Schäfer, Daniel Schiffner
 * 
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XTL
{
    /// <summary>
    /// Internal static helper class.
    /// </summary>
    public class XNAHelper
    {
        /// <summary>
        /// Creates a <see cref="BasicEffect"/> using the given color for diffuse lighing.
        /// </summary>
        /// <param name="GraphicsDevice">The current <see cref="GraphicsDevice"/></param>
        /// <param name="color">The diffuse color in the effect</param>
        /// <returns>Returns a new <see cref="BasicEffect"/></returns>
        public static BasicEffect CreateBasicEffect(GraphicsDevice GraphicsDevice, Color color)
        {
            BasicEffect res = new BasicEffect(GraphicsDevice, null);
            res.DiffuseColor = color.ToVector3();
            res.EnableDefaultLighting();
            res.PreferPerPixelLighting = true;
            return res;
        }

        /// <summary>
        /// Creates a <see cref="BasicEffect"/> using vertex coloring for lighting.
        /// </summary>
        /// <param name="GraphicsDevice">The current <see cref="GraphicsDevice"/></param>
        /// <returns>Returns a new <see cref="BasicEffect"/></returns>
        public static BasicEffect CreateBasicEffect(GraphicsDevice GraphicsDevice)
        {
            BasicEffect res = new BasicEffect(GraphicsDevice, null);
            res.VertexColorEnabled = true;
            return res;
        }

        /// <summary>
        /// Gets a vector containing the GDV colors as floats in range [0,1].
        /// </summary>
        /// <value>A color vector</value>
        public static Vector3 ColorGDVvector3
        {
            get
            {
                return new Vector3(20 / 255f, 101 / 255f, 171 / 255f);
            }
        }

        /// <summary>
        /// Gets the GDV color.
        /// </summary>
        /// <value>The GDV color</value>
        public static Color ColorGDV
        {
            get
            {
                return new Color(20, 101, 171);
            }
        }

        /// <summary>
        /// Toggle to next Fillmode
        /// </summary>
        /// <param name="gd"></param>
        public static void ToggleFillmode(GraphicsDevice gd)
        {
            if (gd.RenderState.FillMode == FillMode.Point)
                gd.RenderState.FillMode = FillMode.Solid;
            else
                if (gd.RenderState.FillMode == FillMode.Solid)
                    gd.RenderState.FillMode = FillMode.WireFrame;
                else
                    gd.RenderState.FillMode = FillMode.Point;
        }
    }
}
